package com.basic.controller;

import com.area.entity.Area;
import com.area.entity.vo.AreaVo;
import com.area.service.IAreaService;
import com.code.domain.CommonResult;
import com.code.domain.GpmartUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@ApiOperation(value = "区块模块",notes = "区块模块")
@Controller
@CrossOrigin
@RequestMapping(value = "/basic/area" )
@Slf4j
public class AreaBasicController {

    @Autowired
    private IAreaService areaService;


    @ApiOperation(value = "前端框架通过Redis进行分页",notes = "前端框架通过Redis进行分页")
    @GetMapping(value = "/queryBasicAreaLayUiRedisPage")
    public @ResponseBody
    CommonResult queryBasicAreaLayUiRedisPage(AreaVo area, HttpServletRequest request, HttpServletResponse response){
        List<Area> countList = areaService.queryAreaList(area);
        List<Area> list = areaService.findAreaPage(GpmartUtil.PageBefore(area.getPage(),area.getLimit()),area.getLimit(),area);
        return new CommonResult(0,"操作成功",countList.size(),list);
    }

    @ApiOperation(value = "查询区域的所有信息",notes = "查询区域的所有信息")
    @GetMapping(value = "/queryBasicAreaAll")
    public @ResponseBody CommonResult queryBasicAreaAll(HttpServletRequest request){
        List<Area> list = areaService.queryBasicAreaAll();
        return new CommonResult(0,"操作成功",list.size(),list);
    }





}